class Solution {
public:
    vector<vector<int>> levelOrder(TreeNode* root) {
queue <TreeNode*> p;
 vector <vector <int>> t;
 int i;
        if (!root) {
            return t;
        }
        p.push(root);
        while (!p.empty()) {
           int c = p.size();
            t.push_back(vector <int> ());
            for (i = 1; i <= c; i++) {
                 auto m= p.front();
                p.pop();
                t.back().push_back(m->val);
                if (m->left) p.push(m->left);
                if (m->right) p.push(m->right);
            }
        }
        return t;
    }
};